<?php
class AppMain
{
	public static function refreshParentFrame()
	{
		ob_clean();
		echo '<script language="javascript">parent.location.href = parent.location.href;</script>';
		exit();
	}
	/**
	$linkFormate like  article.php?page=%d
	*/
	public static function paginationUI($totalPage,$currentPage,$linkFormate,$leftPageNumberLen = 3,$rightPageNumberLen = 3)
	{
		$startPageNumber = $currentPage - $leftPageNumberLen;
		$startPageNumber = $startPageNumber < 1?1:$startPageNumber;
		
		$endPageNumber = $currentPage + $rightPageNumberLen;
		$endPageNumber = $endPageNumber > $totalPage?$totalPage:$endPageNumber;
		
		$nextPageNumber = $currentPage + 1;
		$nextPageNumber = $nextPageNumber > $totalPage?$totalPage:$nextPageNumber;
		
		$prevPageNumber = $currentPage - 1;
		$prevPageNumber = $prevPageNumber < 1?1:$prevPageNumber;
			
			
		echo '<div id="pageh">';
		$firstPageLink = sprintf($linkFormate,$prevPageNumber);
		echo '<div id="pageh-1"><a href="'.$firstPageLink.'"><img width="74" height="29" src="images/pageprev.gif"></a></div>';
		
		echo '<div id="pageh-2"><ul>';
	
		
		if($startPageNumber > 1)
		{
			echo '<li>...</li>';
		}
		for($i=$startPageNumber; $i <= $endPageNumber; $i++)
		{
			if($currentPage == $i)
			{
				echo sprintf("<li>%d</li>",$i);
			}else{
				echo sprintf("<li><a href='$linkFormate'>%d</a></li>",$i,$i);
			}
		}
		if($endPageNumber < $totalPage)
		{
			echo '<li>...</li>';
		}
		echo '</ul></div>';
		
		$lastPageLink = sprintf($linkFormate,$nextPageNumber);
		echo '<div id="pageh-3"><a href="'.$lastPageLink.'"><img width="74" height="29" src="images/pagenext.gif"></a></div>';
		echo '</div>';
	}
	
public static function get_now_relative_client($onlyDate = true)
{
	$offset_hours = AppMain::getSiteOffsetClientHours();
	if($onlyDate)
	{
		return date(constant('WEBSITE_DATE_FORMATE'),strtotime(sprintf("+%d hour",$offset_hours)));
	}else{
		return date(constant('WEBSITE_DATE_TIME_FORMATE'),strtotime(sprintf("+%d hour",$offset_hours)));
	}
}
public static function getSiteOffsetClientHours()
{
	if(!isset($_REQUEST['_cache_global_get_now_relative_client']))
	{
		$_REQUEST['_cache_global_get_now_relative_client_hours'] = intval(Util::getGlobalValue(constant('SITE_TIME_OFFSET_HOURS')));
	}
	return intval($_REQUEST['_cache_global_get_now_relative_client_hours']);
}
public static function getMysqlOffsetClientHours()
{
	return AppMain::getSiteOffsetClientHours();
}
public static function getCurrentDate()
{
	if(!SessionUtil::isExistVar(constant('SESSION_KEY_CURRENT_SELECTED_DATE')))
	{
		SessionUtil::setVar(constant('SESSION_KEY_CURRENT_SELECTED_DATE'),AppMain::get_now_relative_client());
	}
	
	return SessionUtil::getVar(constant('SESSION_KEY_CURRENT_SELECTED_DATE'));
}
public static function setCurrentDate($value)
{
	SessionUtil::setVar(constant('SESSION_KEY_CURRENT_SELECTED_DATE'),$value);
}
}
?>